﻿using DH.Core;
using DH.Core.MapperHelper;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace DH.Web.MVC.Extensions
{
    /// <summary>
    /// 实体集合转ViewModel 集合
    /// </summary>
   public static class ViewModel_Extension
    {

        public static PagedData<TViewModel> ToViewModelPageData<T, TViewModel>(this PagedData<T> pageData)
        {
            if (pageData == null)
            {
                return null;
            }

            var pageViewModelData = new PagedData<TViewModel>();
           
            pageViewModelData.DataList = pageData.DataList.Select(c=> {
                return DHMapper.Map<T, TViewModel>(c);
            }).ToList();
            pageViewModelData.TotalCount = pageData.TotalCount;
            pageViewModelData.CurrentPage = pageData.CurrentPage;
            pageViewModelData.PageSize = pageData.PageSize;

            return pageViewModelData;

        }
    }
}
